import { cloneDeep } from 'lodash';
/**
 * 全局特效参数初始化默认值
 */
const GlobalEffectSettingData = {
  light: {
    illumination: {
      shouldAnimate: true,
      currentTime: 11,
    },
    lightSource: {
      enableLighting: false,
      color: '#ffffff',
      intensity: 1, // 强度
      lightType: 'sunlight',
      direction: [],
      shadows: true,
      softShadows: true, // 柔和度
      darkness: 0.3, // 阴影
      size: 4096,
      maximumDistance: 5000,
    },
  },
  process: [
    { key: 'brightness', label: '全局滤镜', value: { enabled: false, brightness: 0.5 } },
    { key: 'black_and_white', label: '黑白渐变', value: { enabled: false, gradations: 5.0 } },
    {
      key: 'silhouette',
      label: '描边效果',
      value: { enabled: false, color: 'rgba(255, 0, 0, 1)', length: 0.25 },
    },
    {
      key: 'bloom',
      label: '全局泛光',
      value: {
        enabled: false,
        glowOnly: false,
        contrast: 128,
        brightness: -0.3,
        delta: 1.0,
        sigma: 3.78,
        stepSize: 5.0,
      },
    },
    {
      key: 'ambient_occlusion',
      label: '环境光遮蔽',
      value: {
        enabled: false,
        ambientOcclusionOnly: false,
        intensity: 3.0,
        lengthCap: 0.26,
        stepSize: 1.95,
        bias: 0.1,
        blurStepSize: 0.86,
      },
    },
    { key: 'dynamic_fuzzy', label: '动态模糊', value: { enabled: false, kernelWidth: 16 } },
    {
      key: 'night_vision',
      label: '夜视效果',
      value: { enabled: false, color: 'rgba(0, 255, 0, 1)' },
    },
    {
      key: 'depth_field',
      label: '景深效果',
      value: { enabled: false, focalDistance: 87, delta: 1, sigma: 3.78, stepSize: 2.46 },
    },
    {
      key: 'fog',
      label: '雾效设置',
      value: { enabled: false, alpha: 0.2, color: 'rgba(255, 255, 255, 0.8)' },
    },
    { key: 'fxaa', label: '抗锯齿设置', value: { enabled: true } },
  ],
  background: {
    backgroundType: 'bkgImg',
    skybox: null,
    backgroundImage: null,
    color: '',
  },
  environment: {
    normal: [
      {
        key: 'sunny',
        label: '晴',
        params: {
          enable: false,
        },
      },
      {
        key: 'overcast',
        label: '阴',
        value: 1,
        params: {
          enable: false,
          level: 1,
        },
      },
      {
        key: 'rain',
        label: '雨',
        value: 1,
        params: {
          enable: false,
          level: 1,
        },
      },
      {
        key: 'snow',
        label: '雪',
        value: 1,
        params: {
          enable: false,
          level: 1,
        },
      },
      {
        key: 'fog',
        label: '雾',
        value: 1,
        params: {
          enable: false,
          level: 1,
        },
      },
    ],
    other: [
      {
        key: 'sky',
        label: '大气',
        params: {
          enable: false,
        },
      },
      {
        key: 'cloudLayer',
        label: '云层',
        params: {
          enable: false,
          code: Math.random().toString().split('.')[1],
          name: '云层',
          layerName: '云层',
          json: {
            enable: true,
            name: '云层',
            type: 'rectangle',
            datas: [[-180, -90, 180, 90]],
            orbitTheEarth: true,
            images: [require('@/assets/png/earth_cloud.png')],
          },
        },
      },
    ],
  },
};

export const getInitGlobalEffectData = () => {
  return cloneDeep(GlobalEffectSettingData);
};

// 后处理参数范围
export const ProcessRule = {
  brightness: {
    brightness: {
      min: 0,
      max: 10,
      step: 0.01,
    },
  },
  black_and_white: {
    gradations: {
      min: 1,
      max: 63,
      step: 1,
    },
  },
  silhouette: {
    length: {
      min: 0,
      max: 1,
      step: 0.1,
    },
    contrast: {
      min: -255,
      max: 255,
      step: 1,
    },
    brightness: {
      min: -1,
      max: 1,
      step: 0.01,
    },
    delta: {
      min: 1,
      max: 5,
      step: 0.01,
    },
    sigma: {
      min: 1,
      max: 10,
      step: 0.01,
    },
    stepSize: {
      min: 0,
      max: 7,
      step: 0.01,
    },
  },
  ambient_occlusion: {
    intensity: {
      min: 1,
      max: 10,
      step: 1,
    },
    lengthCap: {
      min: 0,
      max: 1,
      step: 0.01,
    },
    stepSize: {
      min: 0,
      max: 7,
      step: 0.01,
    },
    bias: {
      min: 0,
      max: 1,
      step: 0.01,
    },
    blurStepSize: {
      min: 1,
      max: 10,
      step: 0.01,
    },
  },
  dynamic_fuzzy: {
    kernelWidth: {
      min: 0,
      max: 30,
      step: 1,
    },
  },
  depth_field: {
    focalDistance: {
      min: 0,
      max: 500,
      step: 1,
    },
    delta: {
      min: 0.1,
      max: 2,
      step: 0.01,
    },
    sigma: {
      min: 0.5,
      max: 5,
      step: 0.01,
    },
    stepSize: {
      min: 0,
      max: 7,
      step: 0.01,
    },
  },
  fog: {
    alpha: {
      min: 0,
      max: 1,
      step: 0.01,
    },
  },
  fxaa: {},
};

export const SkyBoxImgType = ['morning', 'evening', 'noon', 'night'];

/**
 * 天空图图片映射关系
 */
export const SkyBoxMapping: any = {
  negativeX: 'left',
  positiveX: 'right',
  negativeY: 'front',
  positiveY: 'back',
  negativeZ: 'down',
  positiveZ: 'top',
};
